package com.lovo;

import com.lovo.Ulit.Util;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Doudizhu extends JFrame {


    private List<Card> player1 = new ArrayList();
    private List<Card> player2 = new ArrayList();
    private List<Card> player3 = new ArrayList();
    private List<Card> end = new ArrayList();

    private String[] type = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
    private ArrayList<Card> list = new ArrayList();
    public static void main(String[] args) {
        Doudizhu doudizhu = new Doudizhu();
        doudizhu.init();
        doudizhu.xipai();
        doudizhu.fapai();
        new Doudizhu();

    }

    //初始化
    public void init() {
        for (int i = 0; i < type.length; i++) {
            for (int j = 0; j < 4; j++) {
                list.add(new Card(type[i], i, "/poker/" +  (i+3)+ "_" + (j+1) + ".jpg"));
            }
        }
        list.add(new Card( "大王", 15, "/poker/16_1.jpg"));
        list.add(new Card( "小王", 14, "/poker/17_1.jpg"));

    }

    //洗牌
    public void xipai() {
        Collections.shuffle(list);
        System.out.println(list);

    }

    public void fapai() {
        player1 = list.subList(0, 17);
        player2 = list.subList(17, 34);
        player3 = list.subList(34, 51);
        end = list.subList(51, 54);
        sort(player1);
        sort(player2);
        sort(player3);
        sort(end);
        System.out.println(player1);

    }

    //排序
    public void sort(List list) {
        list.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getNumber() - o2.getNumber();
            }
        });

    }

    public  Doudizhu() {
//        this.setLayout(null);
//        Icon IconImage = Util.getIcon("/poker/3_1.jpg");
//        JLabel imgLable = new JLabel(IconImage);
//        imgLable.setBounds(0, 100, 105, 150);
//        this.add(imgLable);
        int left = 500;
        for (int i = 0; i < player1.size(); i++) {
            String str = player1.get(i).getPath();
            Icon IconImage = Util.getIcon(str);
            JLabel imgLable = new JLabel(IconImage);
            imgLable.setBounds(0, left, 105, 150);
            left -= 30;
            this.add(imgLable);
        }
//        int bottom = 800;
//        for (int i = 0; i < player2.size(); i++) {
//            String str =  player2.get(i).getPath();
//            Icon IconImage = Util.getIcon(str);
//            JLabel imgLable = new JLabel(IconImage);
//            imgLable.setBounds(bottom, 600, 105, 150);
//            bottom -= 30;
//            this.add(imgLable);
//        }
//        int right = 500;
//        for (int i = 0; i < player3.size(); i++) {
//            String str =  player3.get(i).getPath();
//            Icon IconImage = Util.getIcon(str);
//            JLabel imgLable = new JLabel(IconImage);
//            imgLable.setBounds(1000, right, 105, 150);
//            right -= 30;
//            this.add(imgLable);
//        }
//        int center = 550;
//        for (int i = 0; i < end.size(); i++) {
//            String str =  end.get(i).getPath();
//            Icon IconImage = Util.getIcon(str);
//            JLabel imgLable = new JLabel(IconImage);
//            imgLable.setBounds(center, 300, 105, 150);
//            center -= 30;
//            this.add(imgLable);
//        }

        JButton btn1 = new JButton("洗牌");
        btn1.setBounds(350, 380, 100, 20);
        this.add(btn1);
        //设置窗口大小
        this.setSize(1200, 1200);

        //设置窗体标题
        this.setTitle("测试窗口");
        //设置窗口居中
        this.setLocationRelativeTo(null);
        //设置关闭窗口时结束程序
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //设置窗口可见
        this.setVisible(true);
    }


}
